﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Encodings.Web;
using System.Threading.Tasks;

using System.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
using System.Text;
using System.Web;
using OnlineEducation.ExternalService;

namespace OnlineEducation.Extensions
{
    public static class EmailSenderExtensions
    {
        public static Task SendEmailRegister(this IEmailSender emailSender, string email, string accountnumber, string code,
        IWebHostEnvironment hostingEnvironment)
        {

            string content = string.Empty;

            var path = Path.Combine(hostingEnvironment.ContentRootPath, "template", "registeridentitycode.html");

            using (StreamReader sr = new StreamReader(path))
            {
                string s = sr.ReadToEnd();
                content = s.Replace("{0}", accountnumber).Replace("{1}", code);

            }

            return emailSender.SendEmail(email, "注册验证码", content);

        }
        public static Task SendEmailResetPassword(this IEmailSender emailSender, string email, string accountnumber, string code,
      IWebHostEnvironment hostingEnvironment)
        {

            string content = string.Empty;

            var path = Path.Combine(hostingEnvironment.ContentRootPath, "template", "resetpasswordidentitycode.html");

            using (StreamReader sr = new StreamReader(path))
            {
                string s = sr.ReadToEnd();
                content = s.Replace("{0}", accountnumber).Replace("{1}", code);

            }

            return emailSender.SendEmail(email, "重设密码验证码", content);

        }




    }
}
